import { createBrowserRouter, Navigate } from "react-router-dom";
import App from "../App";

import Wjllogin from "../component/wjl/Wjllogin";
import Wjlhome from "../component/wjl/Wjlhome";
import Wjlkaoshi from "../component/wjl/Wjlkaoshi";
import { Look } from "../component/wjl/Look";
let Authcomponent = (props) => {
	let Com = props.children.type;
	if (sessionStorage.getItem("token")) {
		return <Com></Com>;
	} else {
		return <Navigate to="/wjllogin"></Navigate>;
	}
};
let router = createBrowserRouter([
	{
		path: "/",
		element: <App></App>,
		children: [
			{
				path: "/wjllogin",
				element: <Wjllogin></Wjllogin>,
			},
			{
				path: "/wjlhome",
				element: (
					<Authcomponent>
						<Wjlhome></Wjlhome>
					</Authcomponent>
				),
			},
			{
				path: "/wjlkaoshi",
				element: (
					<Authcomponent>
						<Wjlkaoshi></Wjlkaoshi>
					</Authcomponent>
				),
			},
			{
				path: "/look",
				element: (
					<Authcomponent>
						<Look></Look>
					</Authcomponent>
				),
			},
			{
				path: "/",
				element: <Navigate to="/wjllogin"></Navigate>, //重定向
			},
		],
	},
]);

export default router;
